package com.peycard.persistence.dao;

import java.sql.Timestamp;

import javax.ejb.Stateless;
import javax.persistence.Query;

import com.peycard.persistence.PersistenceException;
import com.peycard.persistence.dao.local.ValidSessionDAOLocal;
import com.peycard.persistence.entities.Adsysuser;
import com.peycard.persistence.entities.ValidSession;

/**
 * Session Bean implementation class AsSysUserDAO
 */
@Stateless
public class ValidSessionDAO extends GenericDAOImpl<ValidSession, Long> implements ValidSessionDAOLocal {

    /**
     * Default constructor. 
     */
    public ValidSessionDAO() {
        // TODO Auto-generated constructor stub
    }
    
    public ValidSession findReq(ValidSession vs) throws PersistenceException{
    	try{
    		Query query = getEntityManager().createNamedQuery("findLogin");
			query.setParameter("processingCode", new Integer(20));
			query.setParameter("auditNumber", vs.getSystemTraceAuditNumber());
			ValidSession va = (ValidSession) query.getSingleResult();
			return va;
    	}catch(Exception e){
    		throw new PersistenceException("Error en xx:"+e.getMessage(), e);
    	}
    }
    
    public long tryLogin(String us,int pc,Timestamp datetime) throws PersistenceException{
    	try{
    		Query query = getEntityManager().createNamedQuery("tryLogin");
			query.setParameter("processingCode", pc);
			query.setParameter("us", us);
			query.setParameter("datetime", datetime);
			Long result= (Long) query.getSingleResult();		
			return result;
    	}catch(Exception e){
    		throw new PersistenceException("Error en xx:"+e.getMessage(), e);
    	}
    }
    
    
}
